package com.aku.controller;

import com.aku.entity.Door;
import com.aku.entity.Emp;
import com.aku.service.EmpService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@Controller
public class EmpController {

    @Resource
    private EmpService empService;

    @RequestMapping("/empList")
    public String findAllEmp(Model model){
        List<Emp> emps = empService.findAllEmp();
        model.addAttribute("emps",emps);
        return "emp_list";
    }

    @RequestMapping("/empAdd")
    public String empAdd(Emp emp) {
        empService.addEmp(emp);
        return "redirect:empList";
    }

    @RequestMapping("/empInfo")
    public String empInfo(Integer id, Model model) {
        Emp emp = empService.findEmpById(id);
        model.addAttribute("emp",emp);
        return "emp_update";
    }

    @RequestMapping("/empUpdate")
    public String empUpdate(Emp emp) {
        empService.updateEmp(emp);
        return "redirect:empList";
    }

    @RequestMapping("/empDelete")
    public String empDelete(Integer id) {
        empService.removeEmpById(id);
        return "redirect:empList";
    }
}
